<template>
	<view class="content">
		<u-toast ref="uToast" z-index="30000" />

		<view class="inputGoup">
			<text class="welcomeText">欢迎使用</text>
			<u-form :model="params" :rules="rules" ref="loginParams">
				<u-form-item prop="number" borderBottom><u-input clearable type="text" v-model="params.number" placeholder="请输入账号" border="none"></u-input></u-form-item>
				<u-form-item prop="password" borderBottom>
					<u-input clearable type="password" v-model="params.password" placeholder="请输入密码" border="none"></u-input>
				</u-form-item>
				<u-form-item borderBottom>
					<view class="passwordSty">
						<view @click="changePass">
							<view class="passwordSty_icon">
								<u-icon v-if="!isMemoryPass" name="checkmark-circle" size="18"></u-icon>
								<u-icon v-else name="checkmark-circle-fill" size="18"></u-icon>
							</view>
							<text>记住密码</text>
						</view>
						<view>立即注册</view>
					</view>
				</u-form-item>
				<u-form-item class="btn"><u-button shape="circle" color="rgb(24, 73, 123)" @click="submitLogin">立即登录</u-button></u-form-item>
			</u-form>
		</view>
		<view class="wechatBtn"><u-button shape="circle" color="rgb(45,153,59)" @click="wechatLogin">使用微信登录</u-button></view>
	</view>
</template>

<script>
import { getToken } from '@/utils/auth';
export default {
	onShow: function() {
		// 路由守卫
		const token = getToken();
		if (token) {
			uni.redirectTo({
				url: '/pages/index/index'
			});
		}
	},
	data() {
		return {
			// 是否记住密码
			isMemoryPass: false,
			params: {
				number: 'admin',
				password: '000000',
				isMemoryPass: this.isMemoryPass
			},
			rules: {
				number: {
					type: 'string',
					required: true,
					message: '用户名不能为空',
					trigger: ['blur', 'change']
				},
				password: {
					type: 'string',
					min: 3,
					required: true,
					message: '密码不低于3个字符',
					trigger: ['change', 'blur']
				}
			}
		};
	},
	methods: {
		// 使用微信登录
		wechatLogin() {
			uni.showToast({
				icon: 'error',
				title: '暂未开放！'
			});
			return;
		},
		changePass() {
			this.isMemoryPass = !this.isMemoryPass;
		},
		async submitLogin() {
			// this.$refs.loginParams.validate((valid) => {
			//   if (valid) {
			this.$store.dispatch('user/login', this.params).then(res => {
				uni.showToast({
					title: '登陆成功！',
					icon: 'success',
					mask: true
				});

				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					});
				}, 800);
			});
			//   }
			// });
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	width: 100%;
	height: 100%;
	background-image: url('@/static/images/login_bj.webp');
	background-size: cover;
	background-repeat: no-repeat;
	background-position: center;
	background-attachment: fixed;
	background-color: rgb(24, 73, 123);
	// position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
	align-content: center;
	flex-wrap: wrap;
	.inputGoup {
		// position: absolute;
		// top: 17%;

		width: 550rpx;

		height: 600rpx;
		padding: 28rpx;
		padding-left: 35rpx;
		border-radius: 3%;
		background: rgb(242, 246, 252);
		box-shadow: 10px -10px 0.1 #fff;
		.welcomeText {
			display: inline-block;
			font-size: 20px;
			font-weight: 600;
			margin: 25rpx 0;
		}
		.u-form-item {
			height: 100rpx;
			.passwordSty {
				font-size: 13px;
				width: 100%;
				display: flex;
				flex-wrap: nowrap;
				justify-content: space-between;
				padding-right: 20rpx;
				.passwordSty_icon {
					padding-right: 10rpx;
					float: left;
				}
			}
		}
		.btn {
			padding-top: 50rpx;
		}
	}
	.wechatBtn {
		// width: 100%;
		width: 450rpx;
		margin-top: 100rpx;

		.u-button {
			// width: 420rpx !important;
			height: 60rpx;
			font-size: 22rpx;
		}
	}
}
</style>
